﻿@page
@model Chino.IdentityServer.Pages.Dashboard.Client.ConfigurationModel

@inject  IStringLocalizer<Chino.IdentityServer.Pages.Dashboard.Client.ConfigurationModel> L
@inject IStringLocalizer<Chino.IdentityServer.Pages.Dashboard.ClientsModel> ClientL
@{
    Layout = "_DashboardLayout";
    ViewData["pageName"] = "clients";

    var thisUrl = string.IsNullOrEmpty(Request.Path) ? "~/" : $"~{Request.Path.Value}";
}


<div class="mt-3 container">

    <div class="card-body mb-3 py-0 px-0">
        <nav style="--bs-breadcrumb-divider: '>';" aria-label="breadcrumb">
            <ol class="breadcrumb">
                <li class="breadcrumb-item"><a asp-page="/Dashboard/Clients">@ClientL["breadcrumb_Clients"]</a></li>
                <li class="breadcrumb-item active" aria-current="page">@Model.ClientViewModel.ClientId</li>
            </ol>
        </nav>
    </div>

    <partial name="ValidationSummary" />

    <form method="post">

        @*表单内隐藏内容*@
        <input asp-for="ClientId" hidden /> @*真ID*@

        @*顶部切换Tab*@
        <ul class="nav nav-pills mb-3" id="topNavTab" role="tablist">
            <li class="nav-item" role="presentation">
                <a class="nav-link active" id="home-tab" data-bs-toggle="tab" href="#name_area" role="tab" aria-controls="home" aria-selected="true">@L["tab-name"]</a>
            </li>
            <li class="nav-item" role="presentation">
                <a class="nav-link" id="profile-tab" data-bs-toggle="tab" href="#basics_area" role="tab" aria-controls="profile" aria-selected="false">@L["tab-basics"]</a>
            </li>
            <li class="nav-item" role="presentation">
                <a class="nav-link" id="profile-tab" data-bs-toggle="tab" href="#authentication_area" role="tab" aria-controls="profile" aria-selected="false">@L["tab-authentication"]</a>
            </li>
        </ul>

        @*切换Tab的具体内容在这里*@
        <div class="tab-content" id="topNavTabContent">
        @*名称栏目*@
        <div class="tab-pane fade show active" id="name_area" role="tabpanel" aria-labelledby="name-tab">
            <div class="card shadow-sm">
                <div class="card-header">
                    @L["card_header_client_names"]
                </div>
                <div class="card-body">

                    <div class="mb-3">
                        <label asp-for="ClientViewModel.ClientId" class="form-label">@L["form-client-id"]</label>
                        <input asp-for="ClientViewModel.ClientId" class="form-control" autocomplete="off" />
                        <div><span asp-validation-for="ClientViewModel.ClientId" class="text-danger"></span></div>
                    </div>

                    <div class="mb-3">
                        <label asp-for="ClientViewModel.ClientName" class="form-label">@L["form-client-name"]</label>
                        <input asp-for="ClientViewModel.ClientName" class="form-control" autocomplete="off" />
                        <div><span asp-validation-for="ClientViewModel.ClientName" class="text-danger"></span></div>
                    </div>
                </div>
            </div>
        </div>

        @*基础栏目*@
        <div class="tab-pane fade" id="basics_area" role="tabpanel" aria-labelledby="basics-tab">
            <div class="card shadow-sm">
                <div class="card-header">
                    @L["tab-basics"]
                </div>
                <div class="card-body">
                    @*是否启用*@
                    <div class="mb-3 row">
                        <label asp-for="ClientViewModel.Enabled" class="form-label col-sm-3 col-form-label">
                            @L["Enabled"]
                            <span class="oi oi-comment-square ml-2" data-bs-toggle="tooltip" data-bs-placement="top" title="@L["tips_Enable"]"></span>
                        </label>
                        <div class="col-sm-9">
                            <div class="form-check form-switch">
                                <input asp-for="ClientViewModel.Enabled" class="form-check-input" type="checkbox" autocomplete="off" />
                            </div>
                        </div>
                        <div><span asp-validation-for="ClientViewModel.Enabled" class="text-danger"></span></div>
                    </div>

                    @*Desc*@
                    <div class="mb-3 row">
                        <label asp-for="ClientViewModel.Description" class="form-label col-sm-3 col-form-label">@L["Description"]</label>
                        <div class="col-sm-9">
                            <input asp-for="ClientViewModel.Description" class="form-control" autocomplete="off" />
                        </div>
                        <div><span asp-validation-for="ClientViewModel.Description" class="text-danger"></span></div>
                    </div>

                    @*需要客户端密码*@
                    <div class="mb-3 row">
                        <label asp-for="ClientViewModel.RequireClientSecret" class="col-sm-3 col-form-label">
                            @L["RequireClientSecret"]
                            <span class="oi oi-comment-square ml-2" data-bs-toggle="tooltip" data-bs-placement="top" title="@L["tips_RequireClientSecret"]"></span>
                        </label>
                        <div class="col-sm-9">
                            <div class="form-check form-switch">
                                <input asp-for="ClientViewModel.RequireClientSecret" class="form-check-input" type="checkbox" autocomplete="off" />
                            </div>
                        </div>
                        <div><span asp-validation-for="ClientViewModel.RequireClientSecret" class="text-danger"></span></div>
                    </div>

                    @*需要Pkce*@
                    <div class="mb-3 row">
                        <label asp-for="ClientViewModel.RequirePkce" class="col-sm-3 col-form-label">
                            @L["RequirePkce"]
                            <span class="oi oi-comment-square ml-2" data-bs-toggle="tooltip" data-bs-placement="top" title="@L["tips_RequirePkce"]"></span>
                        </label>
                        <div class="col-sm-9">
                            <div class="form-check form-switch">
                                <input asp-for="ClientViewModel.RequirePkce" class="form-check-input" type="checkbox" autocomplete="off" />
                            </div>
                        </div>
                        <div><span asp-validation-for="ClientViewModel.RequirePkce" class="text-danger"></span></div>
                    </div>

                    @*允许纯文本Pkce*@
                    <div class="mb-3 row">
                        <label asp-for="ClientViewModel.AllowPlainTextPkce" class="col-sm-3 col-form-label">
                            @L["AllowPlainTextPkce"]
                            <span class="oi oi-comment-square ml-2" data-bs-toggle="tooltip" data-bs-placement="top" title="@L["tips_AllowPlainTextPkce"]"></span>
                        </label>
                        <div class="col-sm-9">
                            <div class="form-check form-switch">
                                <input asp-for="ClientViewModel.AllowPlainTextPkce" class="form-check-input" type="checkbox" autocomplete="off" />
                            </div>
                        </div>
                        <div><span asp-validation-for="ClientViewModel.AllowPlainTextPkce" class="text-danger"></span></div>
                    </div>

                    @*离线访问*@
                    <div class="mb-3 row">
                        <label asp-for="ClientViewModel.AllowOfflineAccess" class="col-sm-3 col-form-label">
                            @L["AllowOfflineAccess"]
                            <span class="oi oi-comment-square ml-2" data-bs-toggle="tooltip" data-bs-placement="top" title="@L["tips_AllowOfflineAccess"]"></span>
                        </label>
                        <div class="col-sm-9">
                            <div class="form-check form-switch">
                                <input asp-for="ClientViewModel.AllowOfflineAccess" class="form-check-input" type="checkbox" autocomplete="off" />
                            </div>
                        </div>
                        <div><span asp-validation-for="ClientViewModel.AllowOfflineAccess" class="text-danger"></span></div>
                    </div>

                    @*离线浏览器访问token*@
                    <div class="mb-3 row">
                        <label asp-for="ClientViewModel.AllowAccessTokensViaBrowser" class="col-sm-3 col-form-label">
                            @L["AllowAccessTokensViaBrowser"]
                            <span class="oi oi-comment-square ml-2" data-bs-toggle="tooltip" data-bs-placement="top" title="@L["tips_AllowAccessTokensViaBrowser"]"></span>
                        </label>
                        <div class="col-sm-9">
                            <div class="form-check form-switch">
                                <input asp-for="ClientViewModel.AllowAccessTokensViaBrowser" class="form-check-input" type="checkbox" autocomplete="off" />
                            </div>
                        </div>
                        <div><span asp-validation-for="ClientViewModel.AllowAccessTokensViaBrowser" class="text-danger"></span></div>
                    </div>

                    @*允许的Scopes*@
                    <div class="mb-3 row">
                        <label class="col-sm-3 col-form-label">
                            @L["AllowedScopes"]
                            <span class="oi oi-comment-square ml-2" data-bs-toggle="tooltip" data-bs-placement="top" title="@L["tips_AllowedScopes"]"></span>
                        </label>
                        <div class="col-sm-9">
                            <a class="btn btn-secondary" target="_blank" asp-page="AllowedScopes" asp-route-Id="@Model.ClientId">@L["btn_AllowedScopes"]</a>
                        </div>
                    </div>

                    @*RedirectUris 重定向URI*@
                    <div class="mb-3 row">
                        <label class="col-sm-3 col-form-label">
                            @L["RedirectUris"]
                            <span class="oi oi-comment-square ml-2" data-bs-toggle="tooltip" data-bs-placement="top" title="@L["tips_RedirectUris"]"></span>
                        </label>
                        <div class="col-sm-9">
                            <a class="btn btn-secondary" target="_blank" asp-page="RedirectUris" asp-route-Id="@Model.ClientId">@L["btn_RedirectUris"]</a>
                        </div>
                    </div>

                    @*允许的授权类型*@
                    <div class="mb-3 row">
                        <label class="col-sm-3 col-form-label">
                            @L["AllowedGrantTypes"]
                            <span class="oi oi-comment-square ml-2" data-bs-toggle="tooltip" data-bs-placement="top" title="@L["tips_AllowedGrantTypes"]"></span>
                        </label>
                        <div class="col-sm-9">
                            <a class="btn btn-secondary" target="_blank" asp-page="AllowedGrantTypes" asp-route-Id="@Model.ClientId">@L["btn_AllowedGrantTypes"]</a>
                        </div>
                    </div>

                    @*允许的跨域来源*@
                    <div class="mb-3 row">
                        <label class="col-sm-3 col-form-label">
                            @L["AllowedCorsOrigins"]
                            <span class="oi oi-comment-square ml-2" data-bs-toggle="tooltip" data-bs-placement="top" title="@L["tips_AllowedCorsOrigins"]"></span>
                        </label>
                        <div class="col-sm-9">
                            <a class="btn btn-secondary" target="_blank" asp-page="AllowedCorsOrigins" asp-route-Id="@Model.ClientId">@L["btn_AllowedCorsOrigins"]</a>
                        </div>
                    </div>

                </div>
            </div>
        </div>

        @*名称栏目*@
        <div class="tab-pane fade" id="authentication_area" role="tabpanel" aria-labelledby="name-tab">
            <div class="card shadow-sm">
                <div class="card-header">
                    @L["card_header_client_authentication_area"]
                </div>
                <div class="card-body">
                    <partial name="partials/ConfigurationAuthentication" for="@Model.ClientViewModel" />
                </div>
            </div>
        </div>
    </div>

        @*提交表单的按钮们*@
        <div class="card shadow-sm my-3">
            <div class="card-body">
                <button type="submit" name="button" value="save" class="btn btn-primary">@L["btn_save"]</button>
                <a asp-page="Delete" asp-route-ReturnUrl="~/Dashboard/Clients" asp-route-Id="@Model.ClientId" class="btn btn-danger">@L["btn_del"]</a>
            </div>
        </div>
        
    </form>

    

    

    @*<div class="card mt-3 mb-3 shadow-sm">
            <div class="card-body">
                <a class="btn btn-outline-secondary" asp-page="UserRoles" asp-route-UserId="@Model.UserId">@L["Manage User Roles"]</a>
            </div>
        </div>*@
</div>


@section Scripts {
    @{await Html.RenderPartialAsync("_ValidationScriptsPartial");}

    <script>
        let triggerTabList = [].slice.call(document.querySelectorAll('#topNavTab a'));
        triggerTabList.forEach(function (triggerEl) {
            var tabTrigger = new bootstrap.Tab(triggerEl);

            triggerEl.addEventListener('click', function (event) {
                event.preventDefault()
                tabTrigger.show()
            });
        });


        let tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'))
        let tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
            return new bootstrap.Tooltip(tooltipTriggerEl)
        })
    </script>
}